<!--  -->
<template>
  <div class=''>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisibles"
      width="25%"
      :before-close="handleClose"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item
          :label="'房产编号'"
          prop="projectId"
        >
          <!-- <el-autocomplete
            class="inline-input"
            v-model="ruleForm.projectNumber"
            :fetch-suggestions="querySearch"
            placeholder="请选择房产编号"
            @select="handleSelect"
          ></el-autocomplete> -->
          <el-select
            filterable
            style="width:100%"
            v-model="ruleForm.projectId"
            placeholder="请选择房产编号"
          >
            <el-option
              v-for="(item,index) in options"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          @click="dialogVisibles = false"
          icon='el-icon-circle-close'
        >取 消</el-button>
        <el-button
          icon='el-icon-circle-check'
          type="primary"
          @click="doSubmit"
        >确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { mrpublicmeterrelate, EstateByPublicMeter, saveFloorProject } from '@/api/market/meter/setting/person'
export default {
  name: 'publicAdd',
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data () {
    // 这里存放数据
    return {
      title: '添加楼层信息',
      dialogVisibles: false,
      ruleForm: {
        projectNumber: '',
        projectName: '',
        projectArea: '',
        projectId: ''
      },
      item: {},
      rules: {
        projectNumber: [{ required: true, message: '房产编号不能为空', trigger: 'change' }],
      },
      method: '',
      projectBuildingId: '',
      type: '',
      id: '',
      parentId: '',
      options: []
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    // querySearch (queryString, cb) {
    //   var restaurants = this.options;
    //   var results = queryString ? this.options.filter(this.createFilter(queryString)) : this.options;
    //   // 调用 callback 返回建议列表的数据
    //   cb(results);
    // },
    // handleSelect (item) {
    //   console.log(item);
    // },
    test (value) {
      value = value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')
      return value
    },
    doSubmit () {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          if (this.method == 'add' || this.method == 'edit') {
            if (this.method == 'add') {
              this.ruleForm.publicMeterRelateId = this.parentId
            }
            saveFloorProject(this.ruleForm).then(res => {
              this.dialogVisibles = false
              if (this.method == 'add') {
                this.$message.success("添加成功")
              } else {
                this.$message.success("修改成功")
              }
              this.$emit("getList")
            })
          }
        } else {
          return false
        }
      })
    },
    handleClose () {
      this.dialogVisibles = false
    },
    init (method, id, item, parentId) {
      this.method = method
      this.item = item
      this.id = id
      this.parentId = parentId
      this.ruleForm = {
        projectNumber: '',
        projectName: '',
        projectArea: ''
      }
      if (method == 'edit') {
        this.title = '修改楼层信息'
      }
      EstateByPublicMeter(item).then(res => {
        this.options = res.data.data
      })
      this.dialogVisibles = true
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created () {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted () {

  },
  beforeCreate () { }, // 生命周期 - 创建之前
  beforeMount () { }, // 生命周期 - 挂载之前
  beforeUpdate () { }, // 生命周期 - 更新之前
  updated () { }, // 生命周期 - 更新之后
  beforeDestroy () { }, // 生命周期 - 销毁之前
  destroyed () { }, // 生命周期 - 销毁完成
  activated () { } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style lang='scss' scoped>
//@import url(); 引入公共css类
</style>